(function() {
  function init() {
    var container = document.getElementById('radoi'),
      name = document.getElementById('name'),
      schoolBox = document.getElementById('school-box'),
      city = document.getElementById('city'),
      school = document.getElementById('school'),
      company = document.getElementById('company'),
      inputs = container.getElementsByTagName('input');

    var len = inputs.length;
    for (var i = 0; i < len; i++) {
      inputs[i].onclick = function() {
        var val = this.value;
        if (+val === 1) {
          company.style.display = 'none';
          schoolBox.style.display = '';
          name.innerHTML = '学校';
        } else {
          company.style.display = '';
          schoolBox.style.display = 'none';
          name.innerHTML = '就业单位';
        }
      };
    }

    city.onchange = function() {
      setSchool(this.value);
    };

    inputs[0].click();
    setCity(city);
    setSchool(city.value);
  }

  var schoolData = {
    '北京': ['北京大学', '清华大学'],
    '上海': ['华南大学', '理工大学'],
    '深圳': ['深圳大学', '师范大学']
  };

  function setCity() {
    var str = '';
    for (var i in schoolData) {
      str += '<option value="' + i + '">' + i + '</option>';
    }
    city.innerHTML = str;
  }

  function setSchool(str) {
    var data = schoolData[str];
    var len = data.length;
    var str = '';
    for (var i = 0; i < len; i++) {
      str += '<option value="' + data[i] + '">' + data[i] + '</option>';
    }
    school.innerHTML = str;
  }

  window.onload = init;
})();
